﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Shared;

namespace OficinaTuristicaFE.Controls
{
    /// <summary>
    /// Interaction logic for Container.xaml
    /// </summary>
    public partial class Container : SurfaceUserControl 
    {
        private string _styleSuffix;

        /// <summary>
        /// Gets or sets the suffix for getting the style for the container.
        /// i.e.: "Routes" would create a "LabelStyleRoutes", "StackPanelStyleRoutes"... etc...
        /// </summary>
        public string StyleSuffix
        {
            get { return _styleSuffix; }
            set {
                _styleSuffix = value;
                
              //  ServiceName.Style = (Style)FindResource("LabelStyle" + value);
                ServiceContainer.Style = (Style)FindResource("StackPanelStyle" + value);
            }
        }
        
        /// <summary>
        /// Is the service public or private?? 0-> Private, 1 -> Public
        /// </summary>
        public int publicOrPrivate { get; set; }

       // public string tipoServicio;
        private string _tipoServicos;

        public string tipoServicio
        {
            get { return _tipoServicos; }
            set { _tipoServicos = value; }
        }

        public Container()
        {
            InitializeComponent();
        }

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
        }
        
        public event SelectionChangedEventHandler SelectionChanged;

        public void sbl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SelectionChanged != null)
                SelectionChanged(this, e);
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Fires when the user clicks on the ShowAllOnMap button.
        /// </summary>
        public event RoutedEventHandler ShowAllOnMapClick;

        protected virtual void ShowAllOnMap_Click(object sender, RoutedEventArgs e)
        {
            if (ShowAllOnMapClick != null)
            {
                ShowAllOnMapClick(this, e);
            }
        }

        public event EventHandler<ItemEventArgs> itemSelected;

        TextBlock block;

        private void TextBlock_PreviewContactDown(object sender, ContactEventArgs e)
        {
            block = e.Contact.DirectlyOver as TextBlock;
        }

        private void scrollViewer_ContactTapGesture(object sender, ContactEventArgs e)
        {
            if (block != null && itemSelected != null)
            {
                itemSelected(this, new ItemEventArgs() { DataContext = block.DataContext, DirectlyOver = block, Contact = e.Contact });
            }
        }

    }

    public class ItemEventArgs : EventArgs
    {
        public object DataContext { get; set; }
        public IInputElement DirectlyOver { get; set; }
        public Contact Contact { get; set; }

    }
}